package com.powernode.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powernode.domain.HotSearch;
import com.powernode.service.HotSearchService;
import com.powernode.utils.AuthUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 内容:
 * 作者: cy
 */
@RestController
@RequestMapping("admin/hotSearch")
@Api(tags = "热搜管理")
public class HotSearchController {
    @Autowired
    private HotSearchService hotSearchService;

    @GetMapping("page")
    @ApiOperation("分页查询热搜")
    public ResponseEntity<Page<HotSearch>> loadHotSearchPage(Page<HotSearch> page, HotSearch hotSearch) {
        Page<HotSearch> hotSearchPage = hotSearchService.findHotSearchPage(page, hotSearch);
        return ResponseEntity.ok(hotSearchPage);
    }

    @PostMapping
    @ApiOperation("新增热搜")
    @PreAuthorize("hasAuthority('admin:hotSearch:save')")
    public ResponseEntity<Void> addHotSearch(@RequestBody HotSearch hotSearch) {
        Long shopId = AuthUtil.getUserIdOrShopId(false);
        hotSearch.setShopId(shopId);
        hotSearchService.addHotSearch(hotSearch);
        return ResponseEntity.ok().build();
    }

}
